﻿using System.Linq;
using System.Web;

namespace SecurityModule.Workflows
{
    internal class WFJSFilter : IWorkflow
    {
        public void PreProcess(HttpContext context)
        {
            if (!context.Request.FilePath.StartsWith("/App") && !context.Request.FilePath.StartsWith("/Home")) return;
            if (WhitelsitedPages.Any(wp => wp.Equals(context.Request.FilePath)))
                return;

            context.Response.Filter = new ReplaceFilter(context.Response.Filter,
                                                        context.Response.ContentEncoding,
                                                        content => content.RemoveEventsAndScripts());
        }

        private static readonly string[] WhitelsitedPages = new[]
            {
                "/App",
                "/App/Dashboard",
                "/App/Dashboard/Index",
                "/App/ManageGroups",
                "/App/ManageGroups/Index"
            };


        public void PostProcess(HttpContext context)
        {
        }
    }
}
